package com.example.demo6myapplication;

import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.Touch;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.ToggleButton;

public class demo6MainActivity extends AppCompatActivity {

    private CompoundButton compoundButton;
    private RadioGroup radioGroup;
    private RadioButton radio1,radio2,radio3;
    private CheckBox check1,check2,check3;
    private Button button1,button2;
    private TextView text1,text2,text3,text4;
    private LinearLayout linearLayout;
    private Switch switch1,switch2;
    private ToggleButton toggleButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo6_main);

        final String[] str = new String[100];
        text1 = (TextView)findViewById(R.id.text1);
        text2 = (TextView)findViewById(R.id.text2);
        text3 = (TextView)findViewById(R.id.text3);
        text4 = (TextView)findViewById(R.id.text4);

        radio1=(RadioButton)findViewById(R.id.radio1);
        radio2=(RadioButton)findViewById(R.id.radio2);
        radio3=(RadioButton)findViewById(R.id.radio3);
        radioGroup=(RadioGroup)findViewById(R.id.radiogroup);
        radioGroup.setOnCheckedChangeListener(radioGroupChangeListener);

        button1=(Button)findViewById(R.id.button1);
        button2=(Button)findViewById(R.id.botton2);
        button1.setOnClickListener(buttonOnClickListener);
        button2.setOnClickListener(buttonOnClickListener);

        check1=(CheckBox)findViewById(R.id.check1);
        check2=(CheckBox)findViewById(R.id.check2);
        check3=(CheckBox)findViewById(R.id.check3);
        check1.setOnCheckedChangeListener(checkBoxChangeListener);
        check2.setOnCheckedChangeListener(checkBoxChangeListener);
        check3.setOnCheckedChangeListener(checkBoxChangeListener);

        switch1=(Switch)findViewById(R.id.swich1) ;
        switch2=(Switch)findViewById(R.id.swich2) ;
        switch1.setOnCheckedChangeListener(swichChangeListener);
        switch2.setOnCheckedChangeListener(swichChangeListener);

        toggleButton=(ToggleButton)findViewById(R.id.toggle3);
        toggleButton.setOnCheckedChangeListener(swichChangeListener);

        linearLayout = (LinearLayout)findViewById(R.id.linnnn);





//        radioGroup=(RadioGroup) findViewById(R.id.radiogroup);
//        button2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                text4.setText("");
//                text5.setText("");
//                text6.setText("");
//                text7.setText("");
//                radio1.setChecked(false);
//                radio2.setChecked(false);
//                radio3.setChecked(false);
//                check1.setChecked(false);
//                check2.setChecked(false);
//                check3.setChecked(false);
//            }
//        });

//        compoundButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                int id = compoundButton.getId();
//                switch (id){
//                    case R.id.check1:
//                        text5.setText("你接种了科兴");
//                    case R.id.check2:
//                        text5.setText("你接种了国药");
//                    case R.id.check3:
//                        text5.setText("你接种了康诺希");
//                }
//            }
//        });
//        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
//                int id = radioGroup.getCheckedRadioButtonId();
//                switch(id){
//                    case R.id.radio1:
//                        text4.setText("你是老师"+"\n");
//                        break;
//                    case R.id.radio2:
//                        text4.setText("你是学生"+"\n");
//                        break;
//                    case R.id.radio3:
//                        text4.setText("你不是老师也不是学生"+"\n");
//                        break;
//                }
//            }
//        });
//
//
//        check1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                if(isChecked=true){
//                        text5.setText("是否接种科兴疫苗？              是");
//                }
//                if(isChecked=false){
//                    text5.setText("是否接种科兴疫苗？              否");
//                }
//            }
//        });
//        check2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//
//                if(isChecked=true){
//                    text6.setText("是否接种国药疫苗？             是");
//                }
//                if(isChecked=false){
//                    text6.setText("是否接种国药疫苗？             否");
//                }
//
//            }
//        });
//        check3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//
//
//                if(isChecked=true){
//                    text7.setText("是否接种康诺希疫苗？             是");
//                }
//                if(isChecked=false){
//                    text7.setText("是否接种康诺希疫苗？             否");
//                }
//            }
//        });
   }
   private RadioGroup.OnCheckedChangeListener radioGroupChangeListener =
           new RadioGroup.OnCheckedChangeListener(){
               @Override
               public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                   int id = radioGroup.getCheckedRadioButtonId();
                   switch (id){
                       case R.id.radio1:
                           text4.setText("你是老师");
                           break;
                       case R.id.radio2:
                           text4.setText("你是学生");
                           break;
                       case R.id.radio3:
                           text4.setText("你不是老师也不是学生");
                           break;
                   }
               }
           };

    private CompoundButton.OnCheckedChangeListener checkBoxChangeListener =
            new CompoundButton.OnCheckedChangeListener(){
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    int id = buttonView.getId();
                    switch (id){
                        case R.id.check1:
                            if(isChecked) {
                                text4.setText("你接种了科兴疫苗...");
                            }
                            else{
                                text4.setText("你没有接种科兴疫苗...");
                            }
                            break;
                        case R.id.check2:
                            if(isChecked) {
                                text4.setText("你接种了国药疫苗...");
                            }
                            else{
                                text4.setText("你没有接种国药疫苗...");
                            }
                            break;
                        case R.id.check3:
                            if(isChecked) {
                                text4.setText("你接种了康诺希疫苗...");
                            }
                            else{
                                text4.setText("你没有接种康诺希疫苗...");
                            }
                            break;

                    }
                }
            };


    private CompoundButton.OnCheckedChangeListener swichChangeListener =
            new CompoundButton.OnCheckedChangeListener(){
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    int id = buttonView.getId();
                    switch(id){
                        case R.id.swich1:
                            if(isChecked){
                                text4.setText("忘记上网课让班长叫");
                            }
                            else{
                                text4.setText("忘记上网课不让班长叫");
                            }
                            break;

                        case R.id.swich2:
                            if(isChecked){
                                text4.setText("忘记上网课让舍长叫");
                            }
                            else{
                                text4.setText("忘记上网课不让舍长叫");
                            }
                            break;

                        case R.id.toggle3:
                            if(isChecked){
                                text4.setText("窄屏设置");
                                linearLayout.setOrientation(LinearLayout.VERTICAL);
                                linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
                            }
                            else{
                                text4.setText("宽屏设置");
                                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                                linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
                            }
                            break;

                    }
                }
            };



    private View.OnClickListener buttonOnClickListener =
            new View.OnClickListener(){
                @Override
                public void onClick(View v) {
                    int id = v.getId();
                    switch (id){
                        case R.id.button1:
                            String str = new String("你目前的选择是： \n");

                            str+="1.身份：";
                            switch(radioGroup.getCheckedRadioButtonId()){
                                case R.id.radio1:
                                    str+="老师\n";
                                    break;
                                case R.id.radio2:
                                    str+="学生\n";
                                    break;
                                case R.id.radio3:
                                    str+="其他\n";
                                    break;
                                default:
                                    str+="未选择\n";
                                    break;
                            }

                            str += "2. 您打过的疫苗：";
                            String strTemp = new String("");
                            if(check1.isChecked())
                                strTemp += "国药 ";
                            if(check2.isChecked())
                                strTemp += "科兴 ";
                            if(check3.isChecked())
                                strTemp += "康希诺 ";
                            if(strTemp.isEmpty())
                                strTemp += "(未接清单内疫苗)";
                            str += (strTemp + "\n");

                            str = str + "3. 忘上网课谁叫你：";
                            strTemp = new String("");
                            if(switch1.isChecked())
                                strTemp += "班长 ";
                            if(switch2.isChecked())
                                strTemp += "舍长 ";
                            if(strTemp.isEmpty())
                                strTemp += "(自律好青年)";
                            str += (strTemp + "\n");

                            str = str + "现在的显示模式是：";
                            if(toggleButton.isChecked())
                                str += "窄屏 ";
                            else
                                str += "宽屏 ";

                            text4.setText(str);

                            break;
                        case R.id.botton2:
                            radioGroup.check(-1);
                            check1.setChecked(false);
                            check2.setChecked(false);
                            check3.setChecked(false);
                            switch1.setChecked(false);
                            switch2.setChecked(false);
                            toggleButton.setChecked(false);
                            text4.setText("现在还没有选择！");
                            break;
                    }
                }
            };

}
